package cn.chenfyuan.demoapplication.controller;

import javax.annotation.Resource;

import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.data.redis.core.ReactiveListOperations;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import com.baomidou.mybatisplus.plugins.Page;
import cn.chenfyuan.demoapplication.entity.SysUser;
import cn.chenfyuan.demoapplication.service.SysUserService;

import java.util.List;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author linweijian
 * @since 2018-05-04
 */
@RestController
@RequestMapping("/sysUser")
public class SysUserController {

    @Resource
    private SysUserService ysUserService;
    @Autowired(required = false)
    private ReactiveListOperations<String, List<SysUser>> reactiveListOperations;
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public ResponseEntity<?> queryPage(@RequestParam int pageNum, @RequestParam int pageSize, @ModelAttribute SysUser vo) {
        Page<SysUser> page = ysUserService.selectPage(new Page<>(pageNum, pageSize), vo);
        return new ResponseEntity<>(page, HttpStatus.OK);

    }

    @RequestMapping(value = "/", method = RequestMethod.POST)
    public ResponseEntity<?> add(@RequestBody SysUser vo) {
        return new ResponseEntity<>(ysUserService.insert(vo), HttpStatus.OK);

    }

    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public ResponseEntity<?> delete(@PathVariable("id") String id) {
        return new ResponseEntity<>(ysUserService.deleteById(id), HttpStatus.OK);

    }

    @RequestMapping(value = "/", method = RequestMethod.PUT)
    public ResponseEntity<?> update(@RequestBody SysUser vo) {
        return new ResponseEntity<>(ysUserService.updateById(vo), HttpStatus.OK);
    }
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public ResponseEntity<?> get(@PathVariable("id") String id) {
        return new ResponseEntity<>(ysUserService.get(id), HttpStatus.OK);
    }


}

